package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC80 {


    public int removeDuplicates(int[] arr) {
        if (null == arr || arr.length <= 2) {
            return null == arr ? 0 : arr.length;
        }

        int start = 0, cur = 1, duplicateCount = 1;
        while (cur < arr.length) {
            if (arr[cur] == arr[start] && ++duplicateCount > 2) {
                ++cur;
            } else {
                if (arr[cur] != arr[start]) {
                    duplicateCount = 1;
                }

                arr[++start] = arr[cur++];
            }
        }

        return start + 1;
    }


    public static void main(String[] args) {
        LC80 an = new LC80();
        int[] arr = {1, 1, 1, 2, 2, 3};
        System.out.println(an.removeDuplicates(arr));
    }
}
